package com.aaa.behind.controller;


import com.aaa.behind.service.ITbBannerService;
import com.aaa.entity.TbBanner;
import com.aaa.util.PageInfo;
import com.aaa.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author whj
 * @since 2023-02-01
 */
@RestController
@RequestMapping("/tb-banner")
public class TbBannerController {


    @Autowired
    private ITbBannerService tbBannerService;

    @PostMapping("rotationSearch")
    public Result rotationSearch(@ModelAttribute PageInfo pageInfo, TbBanner tbBanner){
        return new Result(tbBannerService.rotationSearch(pageInfo, tbBanner));
    }

    @GetMapping("deleteBanner/{id}")
    public Result deleteBanner(@PathVariable String id){
        return new Result(tbBannerService.removeById(id));
    }

    @PostMapping("addBanner")
    public Result addBanner(TbBanner tbBanner){
        tbBanner.setIsDisable("0");
        return new Result(tbBannerService.saveOrUpdate(tbBanner));
    }

    @PostMapping("editBanner")
    public Result editBanner(TbBanner tbBanner){
        return new Result(tbBannerService.saveOrUpdate(tbBanner));
    }

    @PostMapping("changeStatus/{id}/{isDisable}")
    public Result changeStatus(@PathVariable String id,@PathVariable String isDisable){
        TbBanner tbBanner = new TbBanner();
        tbBanner.setId(id);
        tbBanner.setIsDisable(isDisable);
        return new Result(tbBannerService.saveOrUpdate(tbBanner));
    }

}

